require("lualib_bundle");
__TS__SourceMapTraceBack(debug.getinfo(1).short_src, {["4"] = 3,["5"] = 3,["6"] = 3,["8"] = 3,["9"] = 10,["10"] = 11,["12"] = 12,["13"] = 12,["14"] = 13,["15"] = 14,["16"] = 12,["19"] = 16,["20"] = 10,["21"] = 23,["22"] = 24,["24"] = 25,["25"] = 25,["26"] = 26,["27"] = 27,["28"] = 28,["29"] = 29,["30"] = 30,["32"] = 33,["33"] = 34,["34"] = 35,["36"] = 37,["37"] = 25,["40"] = 39,["41"] = 23,["42"] = 42,["43"] = 43,["44"] = 44,["46"] = 45,["47"] = 45,["49"] = 46,["50"] = 47,["51"] = 48,["53"] = 50,["54"] = 51,["55"] = 52,["57"] = 55,["58"] = 56,["59"] = 57,["61"] = 60,["62"] = 61,["63"] = 62,["64"] = 63,["65"] = 64,["66"] = 65,["70"] = 45,["73"] = 68,["74"] = 42,["75"] = 3});
local ____exports = {}
____exports.default = __TS__Class()
local ItemUtil = ____exports.default
ItemUtil.name = "ItemUtil"
function ItemUtil.prototype.____constructor(self)
end
function ItemUtil.getAllItemFromUnit(unit)
    local items = {}
    do
        local i = 0
        while i < 6 do
            local item = UnitItemInSlot(unit, i)
            items[i + 1] = item
            i = i + 1
        end
    end
    return items
end
function ItemUtil.getItemAndChargesFromUnit(unit)
    local items = {}
    do
        local i = 0
        while i < 6 do
            local item = UnitItemInSlot(unit, i)
            local itemTypeStr = id2string(GetItemTypeId(item))
            local itemCharges = GetItemCharges(item)
            if not itemCharges or itemCharges < 1 then
                itemCharges = 1
            end
            local oldCharges = items[itemTypeStr]
            if not oldCharges then
                oldCharges = 0
            end
            items[itemTypeStr] = oldCharges + itemCharges
            i = i + 1
        end
    end
    return items
end
function ItemUtil.costItemChargesFromUnit(unit, itemId, charges)
    local costCharges = 0
    local needCostCharges = 0
    do
        local i = 0
        while i < 6 do
            do
                needCostCharges = charges - costCharges
                if costCharges >= charges then
                    return costCharges
                end
                local item = UnitItemInSlot(unit, i)
                if GetItemTypeId(item) ~= itemId then
                    goto __continue10
                end
                local itemCharges = GetItemCharges(item)
                if not itemCharges or itemCharges < 1 then
                    itemCharges = 1
                end
                if itemCharges <= needCostCharges then
                    costCharges = costCharges + itemCharges
                    RemoveItem(item)
                elseif itemCharges > needCostCharges then
                    costCharges = costCharges + needCostCharges
                    SetItemCharges(item, itemCharges - needCostCharges)
                end
            end
            ::__continue10::
            i = i + 1
        end
    end
    return costCharges
end
____exports.default = ItemUtil
return ____exports
